import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  },
  {
    path: '/relation',
    component: Layout,
    redirect: '/relation/user',
    name: '客户管理',
    meta: { title: '客户管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'user',
        name: '用户管理',
        component: () => import('@/views/user/index'),
        meta: { title: '用户管理', icon: 'table' }
      },
      {
        path: 'user/add',
        name: 'addUser',
        hidden:true,
        component: () => import('@/views/user/add'),
        meta: { title: '新增用户', icon: 'table' }
      },
      {
        path: 'user/edit',
        name: 'editUser',
        hidden:true,
        component: () => import('@/views/user/edit'),
        meta: { title: '编辑用户', icon: 'table' }
      },
      {
        path: 'integral',
        name: '积分管理',
        component: () => import('@/views/integral/index'),
        meta: { title: '积分管理', icon: 'table' }
      },
      {
        path: 'integral/add',
        name: 'addIntegral',
        hidden:true,
        component: () => import('@/views/integral/add'),
        meta: { title: '添加积分明细', icon: 'table' }
      },
      {
        path: 'integral/edit',
        name: 'editIntegral',
        hidden:true,
        component: () => import('@/views/integral/edit'),
        meta: { title: '修改积分明细', icon: 'table' }
      }
    ]
  },
  {
    path: '/content',
    component: Layout,
    redirect: '/content/user',
    name: '网站内容管理',
    meta: { title: '网站内容管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'banner',
        name: '轮播图管理',
        component: () => import('@/views/banner/index'),
        meta: { title: '轮播图管理', icon: 'table' }
      },
      {
        path: 'banner/edit',
        name: 'editbanner',
        hidden:true,
        component: () => import('@/views/banner/edit'),
        meta: { title: '编辑轮播图', icon: 'table' }
      },
      {
        path: 'banner/add',
        name: 'addbanner',
        hidden:true,
        component: () => import('@/views/banner/add'),
        meta: { title: '添加轮播图', icon: 'table' }
      },
      {
        path: 'topmenu',
        name: '顶部菜单管理',
        component: () => import('@/views/menu_top/index'),
        meta: { title: '顶部菜单管理', icon: 'table' }
      },
      {
        path: 'topmenu/edit',
        name: 'edittopmenu',
        hidden:true,
        component: () => import('@/views/menu_top/edit'),
        meta: { title: '编辑顶部菜单', icon: 'table' }
      },
      {
        path: 'topmenu/add',
        name: 'addtopmenu',
        hidden:true,
        component: () => import('@/views/menu_top/add'),
        meta: { title: '添加顶部菜单', icon: 'table' }
      },
      {
        path: 'rightmenu',
        name: '右侧菜单管理',
        component: () => import('@/views/menu_right/index'),
        meta: { title: '右侧菜单管理', icon: 'table' }
      },
      {
        path: 'rightmenu/edit',
        name: 'editrightmenu',
        hidden:true,
        component: () => import('@/views/menu_right/edit'),
        meta: { title: '编辑右侧菜单', icon: 'table' }
      },
      {
        path: 'rightmenu/add',
        name: 'addrightmenu',
        hidden:true,
        component: () => import('@/views/menu_right/add'),
        meta: { title: '添加右侧菜单', icon: 'table' }
      },
      {
        path: 'studyType',
        name: '课程类型管理',
        component: () => import('@/views/studyType/index'),
        meta: { title: '课程类型管理', icon: 'table' }
      },
      {
        path: 'studyType/add',
        name: 'addStudyType',
        hidden: true,
        component: () => import('@/views/studyType/add'),
        meta: { title: '添加课程类型', icon: 'table' }
      },
      {
        path: 'studyType/edit',
        name: 'editStudyType',
        hidden: true,
        component: () => import('@/views/studyType/edit'),
        meta: { title: '修改课程类型', icon: 'table' }
      },
      {
        path: 'subject',
        name: '科目管理',
        component: () => import('@/views/subject/index'),
        meta: { title: '科目管理', icon: 'table' }
      },
      {
        path: 'subject/add',
        name: 'addSubject',
        hidden: true,
        component: () => import('@/views/subject/add'),
        meta: { title: '新增科目', icon: 'table' }
      },
      {
        path: 'subject/edit',
        name: 'editSubject',
        hidden: true,
        component: () => import('@/views/subject/edit'),
        meta: { title: '编辑科目', icon: 'table' }
      },
      {
        path: 'grade',
        name: '年级管理',
        component: () => import('@/views/grade/index'),
        meta: { title: '年级管理', icon: 'table' }
      },
      {
        path: 'grade/add',
        name: 'addGrade',
        hidden: true,
        component: () => import('@/views/grade/add'),
        meta: { title: '新增年级', icon: 'table' }
      },
      {
        path: 'grade/edit',
        name: 'editGrade',
        hidden: true,
        component: () => import('@/views/grade/edit'),
        meta: { title: '编辑年级', icon: 'table' }
      },
      {
        path: 'ebook',
        name: '电子书管理',
        component: () => import('@/views/ebook/index'),
        meta: { title: '电子书管理', icon: 'table' }
      },
      {
        path: 'ebook/edit',
        name: 'editebook',
        hidden:true,
        component: () => import('@/views/ebook/edit'),
        meta: { title: '编辑电子书', icon: 'table' }
      },
      {
        path: 'ebook/add',
        name: 'addebook',
        hidden:true,
        component: () => import('@/views/ebook/add'),
        meta: { title: '添加电子书', icon: 'table' }
      },
      {
        path: 'video',
        name: '视频汇总管理',
        component: () => import('@/views/video/index'),
        meta: { title: '视频管理', icon: 'table' }
      },
      {
        path: 'video/addVideo',
        name: 'addVideo',
        hidden:true,
        component: () => import('@/views/video/addVideo'),
        meta: { title: '添加视频汇总', icon: 'table' }
      },
      {
        path: 'video/editVideo',
        name: 'editVideo',
        hidden:true,
        component: () => import('@/views/video/editVideo'),
        meta: { title: '编辑视频汇总', icon: 'table' }
      },
      {
        path: 'video/editVideoInfo',
        name: 'editVideoInfo',
        hidden:true,
        component: () => import('@/views/video/editVideoInfo'),
        meta: { title: '编辑视频列表', icon: 'table' }
      },
      {
        path: 'order',
        name: '订单管理',
        component: () => import('@/views/order/index'),
        meta: { title: '订单管理', icon: 'table' }
      },
      {
        path: 'order/edit',
        name: 'editorder',
        hidden:true,
        component: () => import('@/views/order/edit'),
        meta: { title: '编辑订单', icon: 'table' }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
